Inserting an Image-Based Link
In this section of the article, you will create an image-based link that will either close a browser window or take the visitor to the previous page through the use of JavaScript. Please note that image-based links do not work in Netscape version 4x.
To get started, you will either need to go through the steps discussed on the How to Add a Close Window or Back Link page to create a new page with a different name, or you can delete the link you created in the previous section and reuse the page you have been working on. Either way, you should be starting with a page that has the calendar and table to hold the image-based link. Use the following steps to insert an image-based link into the page:
Insert either the Close Window or Back image into your new table under the calendar. You have a choice of two images to use that are contained in the Source Files download available on the first page of this article. The files to choose from are close1_grey.gif and close2_grey.gif for the Close Window link and back1_darkgrey.gif, back1_lightgrey.gif, back_darkgrey.gif, and back_lightgrey.gif for the Back link. You can also find more images on my website.
To insert the image, place your cursor in the table under the calendar. Click the Insert Image symbol in the toolbar and choose From My Computer... as shown in Figure 7.
Figure 7: Insert Image symbol in the toolbar
- Browse to the image you want to insert (either close1_grey.gif and close2_grey.gif for the Close Window link or back1_darkgrey.gif, back1_lightgrey.gif, back_darkgrey.gif, and back_lightgrey.gif for the Back link), and click Select. The image will be inserted into your page.
Click either the Close Window or Back image under the calendar to select it, click the Insert Link symbol in the toolbar, and choose Drafts and Recent Pages… as shown in Figure 8.
Figure 8: Insert link
Click the Advanced button at the bottom of the Insert Link dialog as shown in Figure 9 to open the bottom part of the dialog.
Figure 9: Insert Link window
-
Type one of the following lines of JavaScript code in the HREF: field. The line of JavaScript you enter depends on whether you have chosen to create a "Close Window" link or a "Back" link. (Don't forget the semicolon at the end of the line!)
For the "Close Window" link, enter:
javascript:window.close();
For the "Back" link, enter:
javascript:history.back();The Insert Link dialog should look like the illustration below (Figure 10) with the JavaScript code in the HREF field.
Figure 10: Add Java Script command
- Click OK to close the Insert Link dialog.
- Preview the page using the F12 key to test the "Close Window" link. If it does not work, go back to the Insert Link window (Figure 10) and check the spelling and punctuation of the JavaScript command.
Publish your page by clicking the Publish button in the upper left corner of Contribute. You will be prompted to choose a file name. Name the file April2003b.htm, and click the publish button to close the Publish New Page dialog.
Caution:
•Never add a "Close Window" link to a page if that page will not be opened in a new window. Doing so would forces the visitor to relaunch her browser and renavigate to your website.
•A "Back" link only works if the page was not opened in a new window.
Nice work! You have successfully used JavaScript with Contribute to create a image-based link that either closes a browser window or returns the visitor to the previous page. In the next section, you will create a Macromedia Flash button-based link that does the same thing.